from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-06-06 14:02:26.418853
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Mon, 06, Jun, 2022
Time: 14:02:36
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -49.5259
Nobs: 679.000 HQIC: -49.8931
Log likelihood: 8436.33 FPE: 1.70200e-22
AIC: -50.1251 Det(Omega_mle): 1.49216e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.307339 0.059171 5.194 0.000
L1.Burgenland 0.105593 0.038375 2.752 0.006
L1.Kärnten -0.109108 0.020204 -5.400 0.000
L1.Niederösterreich 0.199745 0.079889 2.500 0.012
L1.Oberösterreich 0.121241 0.078865 1.537 0.124
L1.Salzburg 0.255766 0.040864 6.259 0.000
L1.Steiermark 0.046658 0.053535 0.872 0.383
L1.Tirol 0.105194 0.043346 2.427 0.015
L1.Vorarlberg -0.060488 0.038142 -1.586 0.113
L1.Wien 0.032675 0.069969 0.467 0.641
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.042232 0.125504 0.337 0.736
L1.Burgenland -0.033179 0.081396 -0.408 0.684
L1.Kärnten 0.039848 0.042854 0.930 0.352
L1.Niederösterreich -0.184932 0.169447 -1.091 0.275
L1.Oberösterreich 0.441157 0.167276 2.637 0.008
L1.Salzburg 0.285288 0.086673 3.292 0.001
L1.Steiermark 0.108724 0.113550 0.957 0.338
L1.Tirol 0.315592 0.091939 3.433 0.001
L1.Vorarlberg 0.026388 0.080901 0.326 0.744
L1.Wien -0.033562 0.148406 -0.226 0.821
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.187744 0.030434 6.169 0.000
L1.Burgenland 0.087974 0.019738 4.457 0.000
L1.Kärnten -0.007542 0.010392 -0.726 0.468
L1.Niederösterreich 0.255258 0.041090 6.212 0.000
L1.Oberösterreich 0.147941 0.040564 3.647 0.000
L1.Salzburg 0.045425 0.021018 2.161 0.031
L1.Steiermark 0.025581 0.027536 0.929 0.353
L1.Tirol 0.086198 0.022295 3.866 0.000
L1.Vorarlberg 0.053184 0.019618 2.711 0.007
L1.Wien 0.119344 0.035988 3.316 0.001
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.110403 0.030622 3.605 0.000
L1.Burgenland 0.043311 0.019860 2.181 0.029
L1.Kärnten -0.013714 0.010456 -1.312 0.190
L1.Niederösterreich 0.185008 0.041344 4.475 0.000
L1.Oberösterreich 0.318643 0.040814 7.807 0.000
L1.Salzburg 0.103172 0.021148 4.879 0.000
L1.Steiermark 0.109988 0.027706 3.970 0.000
L1.Tirol 0.098676 0.022433 4.399 0.000
L1.Vorarlberg 0.062835 0.019740 3.183 0.001
L1.Wien -0.019255 0.036210 -0.532 0.595
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.121422 0.056500 2.149 0.032
L1.Burgenland -0.046440 0.036643 -1.267 0.205
L1.Kärnten -0.046149 0.019292 -2.392 0.017
L1.Niederösterreich 0.145386 0.076282 1.906 0.057
L1.Oberösterreich 0.153650 0.075304 2.040 0.041
L1.Salzburg 0.282550 0.039019 7.241 0.000
L1.Steiermark 0.053470 0.051118 1.046 0.296
L1.Tirol 0.166584 0.041389 4.025 0.000
L1.Vorarlberg 0.096675 0.036420 2.654 0.008
L1.Wien 0.075198 0.066810 1.126 0.260
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.062194 0.044658 1.393 0.164
L1.Burgenland 0.030083 0.028963 1.039 0.299
L1.Kärnten 0.051659 0.015249 3.388 0.001
L1.Niederösterreich 0.203216 0.060295 3.370 0.001
L1.Oberösterreich 0.311216 0.059522 5.229 0.000
L1.Salzburg 0.042716 0.030841 1.385 0.166
L1.Steiermark 0.010232 0.040405 0.253 0.800
L1.Tirol 0.133099 0.032715 4.068 0.000
L1.Vorarlberg 0.067775 0.028787 2.354 0.019
L1.Wien 0.088302 0.052808 1.672 0.094
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.169914 0.053406 3.182 0.001
L1.Burgenland 0.005666 0.034637 0.164 0.870
L1.Kärnten -0.064980 0.018236 -3.563 0.000
L1.Niederösterreich -0.092680 0.072106 -1.285 0.199
L1.Oberösterreich 0.196068 0.071182 2.754 0.006
L1.Salzburg 0.056201 0.036883 1.524 0.128
L1.Steiermark 0.239576 0.048320 4.958 0.000
L1.Tirol 0.503289 0.039123 12.864 0.000
L1.Vorarlberg 0.061351 0.034426 1.782 0.075
L1.Wien -0.072100 0.063152 -1.142 0.254
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.152692 0.059628 2.561 0.010
L1.Burgenland 0.000125 0.038672 0.003 0.997
L1.Kärnten 0.060820 0.020361 2.987 0.003
L1.Niederösterreich 0.188062 0.080506 2.336 0.019
L1.Oberösterreich -0.073529 0.079475 -0.925 0.355
L1.Salzburg 0.210249 0.041180 5.106 0.000
L1.Steiermark 0.133307 0.053949 2.471 0.013
L1.Tirol 0.073304 0.043681 1.678 0.093
L1.Vorarlberg 0.144317 0.038437 3.755 0.000
L1.Wien 0.112744 0.070510 1.599 0.110
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.374978 0.035089 10.687 0.000
L1.Burgenland -0.002394 0.022757 -0.105 0.916
L1.Kärnten -0.022085 0.011981 -1.843 0.065
L1.Niederösterreich 0.214287 0.047374 4.523 0.000
L1.Oberösterreich 0.221488 0.046767 4.736 0.000
L1.Salzburg 0.041302 0.024232 1.704 0.088
L1.Steiermark -0.015540 0.031747 -0.489 0.624
L1.Tirol 0.097587 0.025704 3.796 0.000
L1.Vorarlberg 0.056062 0.022619 2.479 0.013
L1.Wien 0.036195 0.041492 0.872 0.383
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.037727 0.123475 0.181790 0.145300 0.105271 0.087407 0.040615 0.213541
Kärnten 0.037727 1.000000 -0.018238 0.134607 0.053354 0.092410 0.440989 -0.058791 0.094463
Niederösterreich 0.123475 -0.018238 1.000000 0.328871 0.133317 0.286949 0.083608 0.169468 0.306734
Oberösterreich 0.181790 0.134607 0.328871 1.000000 0.223622 0.314158 0.173192 0.159580 0.258623
Salzburg 0.145300 0.053354 0.133317 0.223622 1.000000 0.133307 0.102898 0.119973 0.134062
Steiermark 0.105271 0.092410 0.286949 0.314158 0.133307 1.000000 0.144459 0.123737 0.058341
Tirol 0.087407 0.440989 0.083608 0.173192 0.102898 0.144459 1.000000 0.079011 0.153856
Vorarlberg 0.040615 -0.058791 0.169468 0.159580 0.119973 0.123737 0.079011 1.000000 0.017386
Wien 0.213541 0.094463 0.306734 0.258623 0.134062 0.058341 0.153856 0.017386 1.000000